package com.ymatou.iapi.productmanager.testcase.old;

import com.ymatou.iapi.productmanager.parameter.AddProductInLivesBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.AddProductInLivesCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.*;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.database.model.YmtProductsInLive;
import com.ymttest.database.sqlwapper.YmtLiveWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsInLiveWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

import org.json.JSONObject;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.*;
import java.util.stream.Collectors;

@Ignore
public class Ts_AddProductInLives {
	private static AddProductInLivesCall addProductInLivesCall = new AddProductInLivesCall();
	private static AddProductInLivesBean addProductInLivesBean = new AddProductInLivesBean();

	private static YmtProductsInLiveWapper ymtProductsInLiveWapper = new YmtProductsInLiveWapper();
	private static YmtLiveWapper ymtLiveWapper = new YmtLiveWapper();
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
	
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");	

	private static Integer sellerId1 = 3383;
	private static IntergratedProductMapper intergratedProductMapper = SqlMapperFactory.getIntergratedProductMapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直播中加入商品");
		intergratedProductMapper.updateProductoffSale(sellerId);
		intergratedProductMapper.updateProductoffSale(sellerId);
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(addProductInLivesCall.getOpurl());
	}
	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_001() {
		Logger.start(true,"商品加入正在进行直播");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			int liveId = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			
			double sortMin = 90000000;
			List<YmtProductsInLive> productsInLive = ymtProductsInLiveWapper.selectByLiveId(liveId);
			if (productsInLive.size()>0){
				sortMin = Collections.min(productsInLive.stream().map(x->x.getDreadyputawayproductsort()).collect(Collectors.toList())).doubleValue();
			}
			
			int old_productCount = 0;
			int old_putAwayCount = 0;
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));

			checkAddProductInLive(ret, sellerId,liveId,sortMin,Arrays.asList(productId1,productId2));

			@SuppressWarnings("unchecked")
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			int new_productCount = Integer.parseInt(liveMapUpdate.get("ProductCount").toString());
			int new_putAwayCount = Integer.parseInt(liveMapUpdate.get("PutawayCount").toString());
			
			Logger.verifyEquals(old_productCount+2, new_productCount, "加入直播后，商品数量应更新");
			Logger.verifyEquals(old_putAwayCount+2, new_putAwayCount, "加入直播后，商品数量应更新");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@SuppressWarnings("unchecked")
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_001_001() {
		Logger.start(true,"加入精品直播");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addProdReq.getProduct().setThirdCategoryId(1253);
			addProdReq.getProduct().setSecondCategoryId(1252);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			int liveId = LiveCallService.createLiveInProgress(sellerName, sellerId,1).getJSONObject("Data").getInt("ActivityId");
			
			
			double sortMin = 90000000;
			List<YmtProductsInLive> productsInLive = ymtProductsInLiveWapper.selectByLiveId(liveId);
			if (productsInLive.size()>0){
				sortMin = Collections.min(productsInLive.stream().map(x->x.getDreadyputawayproductsort()).collect(Collectors.toList())).doubleValue();
			}
			
			int old_productCount = 0;
			int old_putAwayCount = 0;
			
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));

			checkAddProductInLive(ret, sellerId,liveId,sortMin,Arrays.asList(productId1,productId2));

			
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			int new_productCount = Integer.parseInt(liveMapUpdate.get("ProductCount").toString());
			int new_putAwayCount = Integer.parseInt(liveMapUpdate.get("PutawayCount").toString());
			
			
			Logger.verifyEquals(old_productCount+2, new_productCount, "加入直播后，商品数量应更新");
			Logger.verifyEquals(old_putAwayCount+2, new_putAwayCount, "加入直播后，商品数量应更新");
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_002() {
		Logger.start(true,"商品加入正在进行直播,已加入商品再次加入");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			
			int liveId = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			
			
			double sortMin = 90000000;
			List<YmtProductsInLive> productsInLive = ymtProductsInLiveWapper.selectByLiveId(liveId);
			if (productsInLive.size()>0){
				sortMin = Collections.min(productsInLive.stream().map(x->x.getDreadyputawayproductsort()).collect(Collectors.toList())).doubleValue();
			}
			
			int old_productCount = 0;
			int old_putAwayCount = 0;
			
			
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));

			checkAddProductInLive(ret, sellerId,liveId,sortMin,Arrays.asList(productId1,productId2));

			
			@SuppressWarnings("unchecked")
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			int new_productCount = Integer.parseInt(liveMapUpdate.get("ProductCount").toString());
			int new_putAwayCount = Integer.parseInt(liveMapUpdate.get("PutawayCount").toString());
			
			
			Logger.verifyEquals(old_productCount+2, new_productCount, "加入直播后，商品数量应更新");
			Logger.verifyEquals(old_putAwayCount+2, new_putAwayCount, "加入直播后，商品数量应更新");
			
			JSONObject ret2 = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));
			checkAddProductInLive(ret2, sellerId,liveId,sortMin,Arrays.asList(productId1,productId2));
			
			
			@SuppressWarnings("unchecked")
			Map<String,Object> liveMapUpdate2 = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			int new_productCount2 = Integer.parseInt(liveMapUpdate2.get("ProductCount").toString());
			int new_putAwayCount2 = Integer.parseInt(liveMapUpdate2.get("PutawayCount").toString());
			
			
			Logger.verifyEquals(old_productCount+2, new_productCount2, "加入直播后，商品数量应更新");
			Logger.verifyEquals(old_putAwayCount+2, new_putAwayCount2, "加入直播后，商品数量应更新");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	
	@SuppressWarnings("unchecked")
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_003() {
		Logger.start(true,"商品加入正在未开始直播");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			int liveId = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			
			double sortMin = 90000000;
			List<YmtProductsInLive> productsInLive = ymtProductsInLiveWapper.selectByLiveId(liveId);
			if (productsInLive.size()>0){
				sortMin = Collections.min(productsInLive.stream().map(x->x.getDreadyputawayproductsort()).collect(Collectors.toList())).doubleValue();
			}
			
			int old_productCount = 0;
			int old_putAwayCount = 0;
			
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));

			checkAddProductInLive(ret, sellerId,liveId,sortMin,Arrays.asList(productId1,productId2));

			
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			int new_productCount = Integer.parseInt(liveMapUpdate.get("ProductCount").toString());
			int new_putAwayCount = Integer.parseInt(liveMapUpdate.get("PutawayCount").toString());
			
			Logger.verifyEquals(old_productCount+2, new_productCount, "加入直播后，商品数量应更新");
			Logger.verifyEquals(old_putAwayCount, new_putAwayCount, "加入直播后，商品数量应更新");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_004() {
		Logger.start(true,"商品加入将来开始直播,已加入商品再次加入");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();

			int liveId = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");

			double sortMin = 90000000;
			List<YmtProductsInLive> productsInLive = ymtProductsInLiveWapper.selectByLiveId(liveId);
			Logger.debug("productsInLive:" + productsInLive);
			if (productsInLive.size()>0){
				sortMin = Collections.min(productsInLive.stream().map(x->x.getDreadyputawayproductsort()).collect(Collectors.toList())).doubleValue();
			}
			
			int old_productCount = 0;
			int old_putAwayCount = 0;
			
			
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));

			checkAddProductInLive(ret, sellerId,liveId,sortMin,Arrays.asList(productId1,productId2));

			
			@SuppressWarnings("unchecked")
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			int new_productCount = Integer.parseInt(liveMapUpdate.get("ProductCount").toString());
			int new_putAwayCount = Integer.parseInt(liveMapUpdate.get("PutawayCount").toString());
			
			
			Logger.verifyEquals(old_productCount+2, new_productCount, "加入直播后，商品数量应更新");
			Logger.verifyEquals(old_putAwayCount, new_putAwayCount, "加入直播后，商品数量应更新");
			
			JSONObject ret2 = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));
			checkAddProductInLive(ret2, sellerId,liveId,sortMin,Arrays.asList(productId1,productId2));
			
			
			@SuppressWarnings("unchecked")
			Map<String,Object> liveMapUpdate2 = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			int new_productCount2 = Integer.parseInt(liveMapUpdate2.get("ProductCount").toString());
			int new_putAwayCount2 = Integer.parseInt(liveMapUpdate2.get("PutawayCount").toString());
			
			
			Logger.verifyEquals(old_productCount+2, new_productCount2, "加入直播后，商品数量应更新");
			Logger.verifyEquals(old_putAwayCount, new_putAwayCount2, "加入直播后，商品数量应更新");
			
			
			
			String productId3 = ProductManagerCallServiceV2.addNewProductOnSale(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			JSONObject ret3 = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId3));
			checkAddProductInLive(ret3, sellerId,liveId,sortMin-2000,Arrays.asList(productId3));
			
			
			@SuppressWarnings("unchecked")
			Map<String,Object> liveMapUpdate3 = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			int new_productCount3 = Integer.parseInt(liveMapUpdate3.get("ProductCount").toString());
			int new_putAwayCount3 = Integer.parseInt(liveMapUpdate3.get("PutawayCount").toString());
			
			
			Logger.verifyEquals(old_productCount+3, new_productCount3, "加入直播后，商品数量应更新");
			Logger.verifyEquals(old_putAwayCount, new_putAwayCount3, "加入直播后，商品数量应更新");
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	@SuppressWarnings("unchecked")
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_005() {
		Logger.start(true,"商品加入已结束直播");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			
			int liveId = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			LiveCallService.closeLive(liveId, sellerId);
			
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));
			Logger.verifyEquals(201, ret.getInt("Code"), "直播已结束，加入直播失败");

			
			
			
			
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			
			Logger.verifyIsNull(liveMapUpdate.get("ProductCount"), "加入直播后，商品数量应更新");
			Logger.verifyEquals(0, Integer.parseInt(liveMapUpdate.get("PutawayCount").toString()), "加入直播后，商品数量应更新");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_006() {
		Logger.start(true,"商品加入已不存在直播");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
		
			JSONObject ret = addProductInLivesCall.call(sellerId,12312341, Arrays.asList(productId1,productId2));
			Logger.verifyEquals(201, ret.getInt("Code"), "直播不存在，加入直播失败");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@SuppressWarnings("unchecked")
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_007() {
		Logger.start(true,"不存在商品加入直播");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = "2222222222";
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			int liveId = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			JSONObject ret = addProductInLivesCall.call(sellerId,liveId, Arrays.asList(productId1,productId2));
			
			Logger.verifyEquals(201, ret.getInt("Code"), "不存在商品加入直播");
			
			
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			Logger.verifyIsNull(liveMapUpdate.get("ProductCount"), "加入直播后，商品数量应更新");
			Logger.verifyEquals(0, Integer.parseInt(liveMapUpdate.get("PutawayCount").toString()), "加入直播后，商品数量应更新");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	@SuppressWarnings("unchecked")
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_008() {
		Logger.start(true,"商品和直播不是同一买手");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			AddSellerProductRequest addProdReq1 =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId1);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq1).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			
			int liveId = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			
			
			
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));
			Logger.verifyEquals(201, ret.getInt("Code"), "商品和直播不是同一买手，加入直播失败");
			

			
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			Logger.verifyIsNull(liveMapUpdate.get("ProductCount"), "加入直播后，商品数量应更新");
			Logger.verifyEquals(0, Integer.parseInt(liveMapUpdate.get("PutawayCount").toString()), "加入直播后，商品数量应更新");
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	

	@SuppressWarnings("unchecked")
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_009() {
		Logger.start(true,"商品库存为0,加入直播");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			SellerProductCallService.updateAllStockNumAs0(sellerId, productId1);
			
			int liveId = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));
			Logger.verifyEquals(201, ret.getInt("Code"), "商品库存为0,加入直播失败");
			

			
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			Logger.verifyIsNull(liveMapUpdate.get("ProductCount"), "加入直播后，商品数量应更新");
			Logger.verifyEquals(0, Integer.parseInt(liveMapUpdate.get("PutawayCount").toString()), "加入直播后，商品数量应更新");
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@SuppressWarnings("unchecked")
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_010() {
		Logger.start(true,"强制下架商品,加入直播");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			ymtProductsIWapper.updateCheckStatus(productId2, -1);
			
			int liveId = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));
			Logger.verifyEquals(201, ret.getInt("Code"), "强制下架商品,加入直播失败");
			

			
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			Logger.verifyIsNull(liveMapUpdate.get("ProductCount"), "加入直播后，商品数量应更新");
			Logger.verifyEquals(0, Integer.parseInt(liveMapUpdate.get("PutawayCount").toString()), "加入直播后，商品数量应更新");
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_011() {
		Logger.start(true,"商品加入直播,精品直播数量达到上限");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			int liveId = LiveCallService.createLiveBeginInFuture(sellerName, sellerId,1).getJSONObject("Data").getInt("ActivityId");
			Logger.comment("liveId:"+liveId);
			ymtLiveWapper.updateProductCountByLiveId(liveId, 99);
			
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));
			Logger.verifyEquals(201, ret.getInt("Code"), "商品加入直播,精品直播数量达到上限");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@SuppressWarnings("unchecked")
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_012() {
		Logger.start(true,"商品加入直播,商品中有保税商品");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			ymtProductsIWapper.updateCatalogStatus(productId2, 4);
			
			int liveId = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1,productId2));
			Logger.verifyEquals(201, ret.getInt("Code"), "商品加入直播,商品中有保税商品");
			
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			Logger.verifyIsNull(liveMapUpdate.get("ProductCount"), "加入直播后，商品数量应更新");
			Logger.verifyEquals(0, Integer.parseInt(liveMapUpdate.get("PutawayCount").toString()), "加入直播后，商品数量应更新");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@SuppressWarnings("unchecked")
	@Ignore
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_013() {
		Logger.start(true,"已删除商品 加入直播");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			SellerProductCallService.batchDeleteProduct(sellerId, Arrays.asList(productId1));
		
			int liveId = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data").getInt("ActivityId");
			JSONObject ret = addProductInLivesCall.call(sellerId,liveId, Arrays.asList(productId1,productId2));
			
			double sortMin = 90000000;
			checkAddProductInLive(ret, sellerId,liveId,sortMin,Arrays.asList(productId2));

			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			int new_productCount = Integer.parseInt(liveMapUpdate.get("ProductCount").toString());
			int new_putAwayCount = Integer.parseInt(liveMapUpdate.get("PutawayCount").toString());
			
			Logger.verifyEquals(1, new_productCount, "加入直播后，商品数量应更新");
			Logger.verifyEquals(1, new_putAwayCount, "加入直播后，商品数量应更新");
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@SuppressWarnings("unchecked")
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductInLives_014() {
		Logger.start(true,"品类不对 加入直播失败");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
		
			int liveId = LiveCallService.createLiveInProgress(sellerName, sellerId,1).getJSONObject("Data").getInt("ActivityId");
			
			//品类不对 加入直播失败
			JSONObject ret = addProductInLivesCall.call(sellerId, liveId, Arrays.asList(productId1));
			Logger.verifyEquals(201, ret.getInt("Code"), "品类不对 加入直播失败");
			
			Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
			Logger.verifyIsNull(liveMapUpdate.get("ProductCount"), "加入直播后，商品数量应更新");
			Logger.verifyEquals(0, Integer.parseInt(liveMapUpdate.get("PutawayCount").toString()), "加入直播后，商品数量应更新");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	//just check product in live table
	public static void checkAddProductInLive(JSONObject ret,int sellerId,int liveId,double sortMin,List<String> productIdList) throws Exception{
		Logger.verifyEquals(200, ret.getInt("Code"), "返回code应为200");
		
		@SuppressWarnings("unchecked")
		Map<String,Object> liveMapUpdate = ymtLiveWapper.selectforMapByLiveId(liveId).get(0);
		boolean isLiveStart = false;
		if (((Date)liveMapUpdate.get("dBeginTime")).before(YMTDateUtil.getDate())&&((Date)liveMapUpdate.get("dEndTime")).after(YMTDateUtil.getDate())){
			isLiveStart = true;
		}
		
		for(int i=0;i<productIdList.size();i++){
			
			String productId = productIdList.get(i);
			
			@SuppressWarnings("unchecked")
			Map<String,Object> liveProductMap = ymtProductsInLiveWapper.selectInLiveByProdIdAndLiveId(productId,liveId).get(0);
			Logger.debug(liveProductMap);


			Logger.verifyEquals(sortMin, Double.parseDouble(liveProductMap.get("dReadyPutawayProductSort").toString()), "ProductInLive - sort");
			Logger.verifyEquals(sellerId, Integer.parseInt(liveProductMap.get("iUserId").toString()), "ProductInLive - iUserId");
			Logger.verifyEquals(liveId, Integer.parseInt(liveProductMap.get("iActivityId").toString()), "ProductInLive - iActivityId");
			Logger.verifyEquals(0, Integer.parseInt(liveProductMap.get("iAction").toString()), "ProductInLive - iaction");
			
			AssertService.assertTime((Date)liveMapUpdate.get("dEndTime"), (Date)liveProductMap.get("dEndTime"), 10,"ProductInLive - endtime");
			
			if (isLiveStart){
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)liveProductMap.get("dStartTime"), 120,"ProductInLive - startTime");
				Logger.verifyEquals(1, Integer.parseInt(liveProductMap.get("iSellStatus").toString()), "ProductInLive - iSellStatus");
			}else{
				AssertService.assertTime((Date)liveMapUpdate.get("dBeginTime"), (Date)liveProductMap.get("dStartTime"), 120,"ProductInLive - startTime");
				Logger.verifyEquals(0, Integer.parseInt(liveProductMap.get("iSellStatus").toString()), "ProductInLive - iSellStatus");
				
			}
			
			NewJavaMongoCheckService.checkLiveMgoSyncBySQL_NewJavaMgo(liveId, productId);
			sortMin = sortMin - 1000;
		}
		
	}
	
	
	
}
